<template>
  <div>
    <HeaderNav title="我的关注" />
    <div class="list">
      <div class="item" v-for="item in list" :key="item.id">
        <img v-if="item.head_img" :src="$axios.defaults.baseURL + item.head_img" alt class="avatar" />
        <img v-else src="@/assets/logo.png" alt class="avatar" />
        <div class="info">
          <div class="name">{{item.nickname}}</div>
          <div class="date">{{item.create_date.split('T')[0]}}</div>
        </div>
        <div class="cancelBtn" @click="cancelFollow(item.id)">取消关注</div>
      </div>
    </div>
  </div>
</template>

<script>
import HeaderNav from "@/components/HeaderNav";
export default {
  data() {
    return {
      list: [],
    };
  },
  components: {
    HeaderNav,
  },
  created() {
    this.loadPage();
  },
  methods: {
    loadPage() {
      this.$axios({
        url: "/user_follows",
      }).then((res) => {
        console.log(res.data);
        // 将数据存放在 data 准备渲染
        this.list = res.data.data;
      });
    },

    cancelFollow(id) {
      this.$axios({
        url: "/user_unfollow/" + id,
      }).then((res) => {
        console.log(res.data);
        // 取消关注完毕的 then 回调里面
        // 重新获取数据即可
        this.loadPage();
      });
    },
  },
};
</script>

<style lang="less" scoped>
.list {
  .item {
    align-items: center;
    padding: 20/360 * 100vw;
    border-bottom: 1px solid #e4e4e4;
    display: flex;
    .avatar {
      height: 40/360 * 100vw;
      width: 40/360 * 100vw;
      object-fit: cover;
      border-radius: 50%;
    }
    .info {
      flex: 1;
      padding-left: 10/360 * 100vw;
      .name {
        font-size: 16/360 * 100vw;
        color: #333;
      }
      .date {
        font-size: 14/360 * 100vw;
        color: #888;
      }
    }
    .cancelBtn {
      background: #e4e4e4;
      font-size: 14/360 * 100vw;
      line-height: 28/360 * 100vw;
      padding: 0 14/360 * 100vw;
      border-radius: 14/360 * 100vw;
    }
  }
}
</style>